package com.example.daimaozi;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         final HatView hatView=new HatView(MainActivity.this);
        hatView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                hatView.hatx=event.getX()-40;
                hatView.haty=event.getY()-200;
                hatView.invalidate();
                return true;
            }
        });
        RelativeLayout relativeLayout=findViewById(R.id.rela);
        relativeLayout.addView(hatView);
    }
}